﻿using System.Linq;
using DevExpress.XtraEditors;

namespace Zdm.Crm.Client.Winform.Utilies
{
    public class EditUtil
    {
        /// <summary>
        /// Reset Edit
        /// </summary>
        /// <param name="be"></param>
        public static void ResetEdit(params BaseEdit[] be)
        {
            foreach (var baseEdit in be)
            {
                baseEdit.EditValue = null;
            }
        }


        /// <summary>
        /// ReadonlyEdit
        /// </summary>
        /// <param name="readOnly"></param>
        /// <param name="be"></param>
        public static void ReadonlyEdit(bool readOnly, params BaseEdit[] be)
        {
            foreach (var baseEdit in be)
            {
                baseEdit.Properties.ReadOnly = readOnly;
            }
        }

        /// <summary>
        /// 必填项校验
        /// </summary>
        /// <param name="be"></param>
        /// <returns></returns>
        public static bool Verify(params BaseEdit[] be)
        {
            if (VerifyWithNoAlert(be))
            {
                XtraMessageBox.Show("缺少必填项！");
                return true;
            }
            return false;
        }

        /// <summary>
        /// 必填项校验
        /// </summary>
        /// <param name="be"></param>
        /// <returns></returns>
        public static bool VerifyWithNoAlert(params BaseEdit[] be)
        {
            return be.Any(baseEdit => baseEdit.EditValue == null || baseEdit.EditValue.ToString() == "");
        }
    }
}
